import axios from "axios";
import qs from "qs";
import config from "./config";
let {host,appKey,accessToken,CategoryId} = config;


export function uploadPhoto(token,data){//上传头像
   return axios.post(`${host}/api/Core/v200/appUser/Photo?appKey=${appKey}&accessToken=${token}`,data)
}


export function delPost(token,postid){ //删除投稿
    return axios.delete(`${host}/Api/Personal/v200/Post/Post?appKey=${appKey}&appAccessToken=${token}&postId=${postid}`);
}


export function createSubPost(token,postid,data){  //投稿
     return axios.post(`${host}/api/Personal/v200/Post/CreateSubPost?appKey=${appKey}&accessToken=${token}&parentPostId=${postid}`,data);
}

export function postVideo(token,postid,data){ //上传视频
     return axios.post(`${host}/api/Personal/v200/Post/Video?appKey=${appKey}&appAccessToken=${token}&postId=${postid}`,data)
}

export function postImg(token,postid,data){  //上传照片
     return axios.post(`${host}/api/Personal/v200/Post/Photo?appKey=${appKey}&appAccessToken=${token}&postId=${postid}`,data) 
}



export function Likepost(token,postid){  //帖子点赞
    return axios.post(`${host}/api/Personal/v200/Post/Likepost?appKey=${appKey}&accessToken=${token}&postId=${postid}`)
}


export function unLikepost(token,postid){  //帖子取消点赞
    return axios.post(`${host}/api/Personal/v200/Post/Unlike?appKey=${appKey}&accessToken=${token}&postId=${postid}`)
}





export function LikeComment(token,id){  //评论点赞
    return axios.post(`${host}/api/Personal/v200/Post/LikeComment?appKey=${appKey}&accessToken=${token}&commentId=${id}`)
}

export function UnLikeComment(token,id){  //评论点赞
    return axios.post(`${host}/api/Personal/v200/Post/UnLikeComment?appKey=${appKey}&accessToken=${token}&commentId=${id}`)
}


export function getUserInfo(token){  //获取用户信息
    return axios.get(`${host}/api/Core/v200/appUser/Get?appKey=${appKey}&accessToken=${token}`)
}

export function sendCode(tel){  //发送验证码
    return axios.get(`${host}/api/Core/v200/appUser/TAC?appKey=${appKey}&phoneNumber=${tel}&tacType=0&phoneCountryCode=86&isRequiredUser=false`);
}

export function checkCode(tel,messageId,tac){  //核销验证码
    return axios.get(`${host}/api/Core/v200/appUser/VerifyTAC?appKey=${appKey}&phoneNumber=${tel}&messageId=${messageId}&tac=${tac}&phoneCountryCode=86`);
}


export function updateUserinfo(token,data){  //更新用户信息
    return axios.post(`${host}/Api/Core/v200/AppUser/Update/?appKey=${appKey}&accessToken=${token}`,data);
}



export function getComment(token,postid,page){  //获取评论
    return axios.get(`${host}/api/Personal/v200/Post/getcomments?appKey=${appKey}&accessToken=${token}&postId=${postid}&take=10&skip=${page}&isGetFanClub=true&showXp=true`);  
}

export function createComment(token,postid,data){  //提交评论
   return axios.post(`${host}/api/Personal/v200/Post/createcomment?appKey=${appKey}&accessToken=${token}&postId=${postid}`,data);
}




export function authLogin(data){//第三方登录
  return axios.post(`${host}/api/Core/v200/appUser/LoginOAuth?appKey=${appKey}`,qs.stringify(data));
}

export function getCourseList(page,take=9){  //获取热门列表
   return axios.get(`${host}/api/Personal/v200/Post/GetPosts?appKey=${appKey}&accessToken=${accessToken}&categoryId=${CategoryId}&skip=${page}&take=${take}`);
}

export function getRankList(page){  //获取排行列表

   return axios.get(`https://game.jixiucloud.cn/api/Games/Documents?appID=424&cName=rank&take=999&skip=${page}&sort={heatcount:-1}&api-version=2`);

}


export function getcourselist(id){  //获取课程系列
   return axios.get(`https://game.jixiucloud.cn/api/Games/Documents?appID=424&filter={"courseid":${id}}&api-version=2&cName=news`)
}

export function getDetail(id){   //获取课程详情
   return axios.get(`${host}/api/Personal/v200/Post/GetPost?appKey=${appKey}&accessToken=${accessToken}&postId=${id}`)
}


export function getWorkDetail(token,id){   //获取作业详情
   return axios.get(`${host}/api/Personal/v200/Post/GetPost?appKey=${appKey}&accessToken=${token}&postId=${id}`)
}
                                                             


export function getGoodWork(postid){  //优秀作业列表
   return axios.get(`${host}/api/Personal/v200/post/getsubposts?take=15&skip=0&appKey=${appKey}&accessToken=${accessToken}&sortType=0&parentPostId=${postid}`);
}


export function myWork(postid,token,userId){  //我的作业
   return axios.get(`${host}/api/Personal/v200/post/getsubposts?take=1&skip=0&appKey=${appKey}&accessToken=${token}&sortType=0&parentPostId=${postid}&targetAppUserId=${userId}`);
}


export function getGoodWorkList(postid,page){  //优秀作业列表
   return axios.get(`${host}/api/Personal/v200/post/getsubposts?take=10&skip=${page}&appKey=${appKey}&accessToken=${accessToken}&sortType=0&parentPostId=${postid}`);
}






export function getUserInfoadmin(token){  //获取用户信息houtai
   return axios.get(`https://www.jixiuapp.com/api/Core/v200/appUser/Get?appKey=qNWmtuX04JGyG-vNLK84V6uUMNPY8lZHR473dXAWiiy9ZT7oOrxxJ2MUCzeaOwzTZH8paczG1O6gzkIYUDa9Ug&accessToken=${token}`)
}





export function getnewsList(name){  //获取排行列表
   return axios.get(`https://game.jixiucloud.cn/api/Games/Documents?appID=424&cName=${name}&take=999&skip=0&api-version=2`);
}
export function getRankDetail(id,name){  //获取
   let filter = ''
   if(id){
      filter = `&filter={_id:{"$oid":"${id}"}}`
   }else{
      filter = ''
   }
  
   return axios.get(`https://game.jixiucloud.cn/api/Games/Documents?appID=424${filter}&cName=${name}&api-version=2`);
}


export function updataRank(id,data,name){  //更新
   let filter = ''
   if(id){
      filter = `&filter={_id:{"$oid":"${id}"}}`
   }else{
      filter = ''
   }
   if(id){
      return axios.put(`https://game.jixiucloud.cn/api/Games/Document?appID=424&cName=${name}${filter}&api-version=2`,data,{
      headers: {
         'Content-Type': 'application/json'
     }
   });
   }else{
      return axios.post(`https://game.jixiucloud.cn/api/Games/Document?appID=424&cName=${name}${filter}&api-version=2`,data,{
      headers: {
         'Content-Type': 'application/json'
     }
   });
   }
      
   
}
export function deleteRank(id){  //删除
   return axios.delete(`https://game.jixiucloud.cn/api/Games/Document?appID=424&cName=rank&filter={_id:{"$oid":"${id}"}}&api-version=2`);
}
export function deletecourse(id){  //删除
   return axios.delete(`https://game.jixiucloud.cn/api/Games/Document?appID=424&cName=news&filter={_id:{"$oid":"${id}"}}&api-version=2`);
}
export function jixiucloudlogin(data){  //删除
   return axios.post(`https://game.jixiucloud.cn/connect/token`,qs.stringify(data));
}